package org.ccahouse.ccatrain.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.ccahouse.ccacommons.common.RestResult;
import org.ccahouse.ccatrain.dto.UserDto;
import org.ccahouse.ccatrain.dto.UserListDto;
import org.ccahouse.ccatrain.dto.UserListPageDto;
import org.ccahouse.ccatrain.entity.User;
import org.ccahouse.ccatrain.service.IUserService;
import org.ccahouse.ccacommons.base.BaseController;
import org.ccahouse.ccatrain.service.impl.UserServiceImpl;
import org.ccahouse.ccatrain.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 描述：
 *
 * @author kevin
 * @since 2020-07-04
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户信息")
public class UserController extends BaseController {

    @Autowired
    private IUserService userService;


    @GetMapping("/page")
    @ApiOperation(value = "分页查询用户列表", response = User.class)
    public RestResult getUserPage(UserListPageDto param) {
            return userService.getUserPage(param);
    }

    @GetMapping("/list")
    @ApiOperation(value = "查询全部用户列表", response = User.class)
    public RestResult getUserList(UserListDto param) {
        return userService.getUserList(param);
    }

    @GetMapping("/details/{id}")
    @ApiOperation(value = "根据id查询用户详情", response = User.class)
    public RestResult getUserById(@PathVariable Integer id) {
        return userService.getUserById(id);
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增用户", response = RestResult.class)
    public RestResult saveUser(@RequestBody UserDto user) {
        return userService.saveUser(user);
    }

    @PostMapping("/saveBatch")
    @ApiOperation(value = "批量新增用户", response = RestResult.class)
    public RestResult saveUsers(@RequestBody List<UserDto> users) {
        return userService.saveUsers(users);
    }

    @PutMapping("/updateBatchByIds")
    @ApiOperation(value = "根据ID批量更新用户", response = RestResult.class)
    public RestResult updateUsersById(@RequestBody List<UserDto> users) {
        return userService.updateUsersById(users);
    }

    @PutMapping("/updateByParams")
    @ApiOperation(value = "根据参数更新用户", response = RestResult.class)
    public RestResult updateUser(@RequestBody UserDto user) {
        return userService.updateUser(user);
    }

    @PostMapping("/saveOrUpdateBatch")
    @ApiOperation(value = "批量插入或批量更新用户信息", response = RestResult.class)
    public RestResult saveOrUpdateUsers(@RequestBody List<UserDto> users) {
        return userService.saveOrUpdateUsers(users);
    }

    @GetMapping("/detail")
    @ApiOperation(value = "根据Id查询用户", response = UserVo.class)
    public RestResult getUesrById(@RequestParam Integer id) {
        return userService.getUesrByParam(id);
    }

    @PostMapping("/listByIds")
    @ApiOperation(value = "根据ids查询用户列表", response = UserVo.class)
    public RestResult getUsersByIds(@RequestBody List<Integer> ids) {
        return userService.getUsersByIds(ids);
    }

    @PostMapping("/saveBatch2")
    @ApiOperation(value = "批量新增用户", response = RestResult.class)
    public RestResult saveUsers2(@RequestBody List<UserDto> users) {
        return userService.saveUsers2(users);
    }
}
